package com.taiyuan.tongcheng.ui;

import org.kymjs.kjframe.KJActivity;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import cn.jpush.android.api.JPushInterface;

import com.taiyuan.tongcheng.application.AppConfig;
import com.taiyuan.tongcheng.application.TCBroadcastAction;
import com.taiyuan.tongcheng.util.DialogUtil;
import com.taiyuan.tongcheng.util.SharePreferenceUtil;
import com.taiyuan.tongcheng.widget.dialog.TcBuilder;
import com.tytc56.user.R;

public class BaseActivity extends KJActivity{
	protected  Button   backBtn;
	protected  TextView topTv;
	protected  TextView rightTv;
	protected  Dialog  progressDialog;
	protected  Dialog  TcLoaddingDialog;
	protected  TcBuilder tcInformDialog;   
	protected  SharePreferenceUtil spUtil;

	@Override
	public void setRootView() {
		
	}
	
	@Override
	protected void onResume() {
		super.onResume();
		JPushInterface.onResume(this);
	}

	@Override
	protected void onPause() {
		super.onPause();
		JPushInterface.onPause(this);
	}
	
	private OnClickListener mClickListener = new OnClickListener() {
		@Override
		public void onClick(View v) {
			switch (v.getId()) {
			case R.id.btn_common_back:
				finish();
				break;

			default:
				break;
			}
		}

	};

	protected void initView() {
		backBtn=(Button)this.findViewById(R.id.btn_common_back);
		topTv=(TextView)this.findViewById(R.id.tv_common_title);
		rightTv=(TextView)this.findViewById(R.id.tv_common_instruction);
		spUtil= new SharePreferenceUtil(BaseActivity.this, AppConfig.SHARE_NAME);
		backBtn.setOnClickListener(mClickListener);
		progressDialog=DialogUtil.getLoginDialog(BaseActivity.this);
		TcLoaddingDialog=DialogUtil.getTcLoadding(BaseActivity.this);
	}
	
	
	/** 显示自定义Toast提示(来自String) **/
	protected void showCustomToast(String text) {
		View toastRoot = LayoutInflater.from(BaseActivity.this).inflate(
				R.layout.layout_common_toast, null);
		((TextView) toastRoot.findViewById(R.id.toast_text)).setText(text);
		Toast toast = new Toast(BaseActivity.this);
		toast.setGravity(Gravity.BOTTOM, 0, 100);
		toast.setDuration(Toast.LENGTH_SHORT);
		toast.setView(toastRoot);
		toast.show();
	}
	
	/** 显示自定义Toast提示(来自String) **/
	protected void showErroCustomToast(String text) {
		View toastRoot = LayoutInflater.from(BaseActivity.this).inflate(
				R.layout.layout_common_error_toast, null);
		((TextView) toastRoot.findViewById(R.id.toast_text)).setText(text);
		Toast toast = new Toast(BaseActivity.this);
		toast.setGravity(Gravity.BOTTOM, 0, 100);
		toast.setDuration(Toast.LENGTH_SHORT);
		toast.setView(toastRoot);
		toast.show();
	}
	
	protected void showinformDialog(String titleMsg ,String msgContent ,View.OnClickListener okClick,View.OnClickListener cancelClick) {
		tcInformDialog=TcBuilder.getInstance(this,1).setButton1Click(okClick).setButton2Click(cancelClick).withTitle(titleMsg).withContent(msgContent);
		tcInformDialog.show();
		tcInformDialog.setCancelable(false);
	}
	
	protected void showSingleDialog(String titleMsg ,String msgContent ,View.OnClickListener okClick) {
		tcInformDialog=TcBuilder.getInstance(this,1).setButton1Click(okClick).withButton1Text("确定").withTitle(titleMsg).withContent(msgContent);
		tcInformDialog.show();
		tcInformDialog.setCancelable(false);
	}
	
	
	protected void cancelInformDialog() {
         if(tcInformDialog!=null&&tcInformDialog.isShowing()){
        	 tcInformDialog.cancel();
         }
	}
	
	protected void  GotoMain() {
//		 startActivity(new Intent(this,MainActivitySlide.class));
		 sendBroadcast(new Intent(TCBroadcastAction.SUCCESS_LOGIN));
		 finish();
	}
	
	protected void  GotoLogin(){
         startActivity(new Intent(this,LoginActivity.class));
	}

	/** 通过Class跳转界面 **/
	protected void startActivity(Class<?> cls) {
		startActivity(cls, null);
	}

	/** 含有Bundle通过Class跳转界面 **/
	protected void startActivity(Class<?> cls, Bundle bundle) {
		Intent intent = new Intent();
		intent.setClass(this, cls);
		if (bundle != null) {
			intent.putExtras(bundle);
		}
		startActivity(intent);
	}

	/** 通过Action跳转界面 **/
	protected void startActivity(String action) {
		startActivity(action, null);
	}

	/** 含有Bundle通过Action跳转界面 **/
	protected void startActivity(String action, Bundle bundle) {
		Intent intent = new Intent();
		intent.setAction(action);
		if (bundle != null) {
			intent.putExtras(bundle);
		}
		startActivity(intent);
	}
	
}
